<template>
	<view>
		<u-sticky><u-button type="primary" :plain="true" icon="https://project.gxrunxiang.com/cdn/change.png" @click="gotochange">编辑</u-button></u-sticky>
		<u-collapse ref='coll' :value="['1','2']">
			<u-collapse-item name="1" title="设备信息" icon="order">
				<u-cell-group>
					<u-cell title="名称" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Name || " "}}</span>
					</u-cell>
					<u-cell title="Mac地址" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Addr || " "}}</span>
					</u-cell>
<!-- 					<u-cell title="编号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.No || " "}}</span>
					</u-cell> -->
					<u-cell title="类型" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Type || " "}}</span>
					</u-cell>
<!-- 					<u-cell title="端口数" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Points || " "}}</span>
					</u-cell> -->
					<u-cell title="型号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Model || " "}}</span>
					</u-cell>
					<u-cell title="厂商" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Factory || " "}}</span>
					</u-cell>
					<u-cell title="起始U(从下往上)" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.U || " "}}</span>
					</u-cell>
					<u-cell title="结束U" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.U2 || " "}}</span>
					</u-cell>
					<u-cell title="机柜编号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.ShelfNo || " "}}</span>
					</u-cell>
					<u-cell title="位于机柜前后" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.IsFront || " "}}</span>
					</u-cell>
<!-- 					<u-cell title="网络类型" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.NetType || " "}}</span>
					</u-cell> -->
					<u-cell title="备注" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Remark || " "}}</span>
					</u-cell>
<!-- 					<u-cell title="纬度" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Lat || " "}}</span>
					</u-cell>
					<u-cell title="经度" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Lng || " "}}</span>
					</u-cell> -->
				</u-cell-group>
			</u-collapse-item>
			<u-collapse-item name="2" title="设备照片">
				<u-album :urls="imagesurls1"></u-album>
			</u-collapse-item>
			<u-button v-if="user.Roles.indexOf('故障填报角色')!=-1 || user.Roles.indexOf('故障审核角色')!=-1" type='error'
				@click="showconfirm=true">删除
			</u-button>
			<u-modal :content="'确定要删除吗？'" :show="showconfirm" showCancelButton closeOnClickOverlay
				@confirm="del" @cancel="showconfirm=false" @close="showconfirm=false"></u-modal>
		</u-collapse>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		mapGetters
	} from 'vuex'
	import {
		getlineequlist,
		getfilebyoutid,
		deletelineequ,
	} from '@/common/api.js'
	export default {
		data() {
			return {
				equid: "",
				equdata: [],
				imagesurls1 : [],
				modalShow: false,
				delmodalShow: false,
				user: {},
				showconfirm: false,
				NodeId: "",
			}
		},
		onLoad(option) {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.equid = option.Id
			this.NodeId = option.NodeId
			getfilebyoutid(option.Id).then(res => {
				for (var i = 0; i < res.length; i++) {
						this.imagesurls1.push(`${baseUrl}/SysFile/download?id=${res[i].Id}`)
				}
				setTimeout(() => {
						// console.log(this.$refs.coll)
						this.$refs.coll.init()	
					},
					500)
			})
			this.getlist(this.equid)
		},
		methods: {
			async getlist(id) {
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: id
				})
				await getlineequlist(para).then(res => {
					this.equdata = res.data[0]			
				})
			},
			del() {
				let ids = []
				ids.push(this.equid)
				deletelineequ(ids).then((res) => {
					if (res == true)
						uni.navigateBack()
				})
			},
			gotochange(){
				uni.redirectTo({url: `/pages/index/addlineequ?Id=${this.equdata.Id}`})
			},
		}
	}
</script>
<style>
	.cell-label {
		margin-top: 10px;
		font-size: 14px;
		color: #909193;
	}
</style>